package com.test.service.impl;

import com.test.dao.IHouseValveCurrentDao;
import com.test.model.HouseValveCurrentData;
import com.test.service.IHouseValueCurrentService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.Date;
import java.util.List;
import java.util.Map;

/**
 * Created by ZZF on 2017/7/5.
 */
@Service
public class HouseValveCurrentServiceImpl implements IHouseValueCurrentService {

    @Autowired
    IHouseValveCurrentDao houseValueCurrentDao;

    @Override
    public void updateSwitchState() {

        List<HouseValveCurrentData> all = houseValueCurrentDao.getAll(HouseValveCurrentData.class);

        for (HouseValveCurrentData houseValveCurrentData : all) {
            boolean switchState=true;

            int random = (int)( Math.random() * 10);
            if (random > 6) {
                switchState = false;
            }
            //给户阀的开关状态设置一个随机值
            houseValveCurrentData.setSwitchState(switchState);

            houseValveCurrentData.setPlanTime(new Date());

            houseValueCurrentDao.update(houseValveCurrentData);
        }


    }

    @Override
    public Map<String, Object> findSwitchState(int houseValueId) {


        return houseValueCurrentDao.findSwitchState(houseValueId);
    }
}
